<?php

App::uses('AppModel', 'Model');

class Data extends AppModel {
	
	public $name = 'Data';
	public $useTable = 'data';
	
	public function getCompanyData($flatten=false) {
		return $this->getByKeyIndex('company', $flatten);
	}
	
	public function getByKeyIndex($index, $flatten=false) {
	    $res = $this->find('all', array('conditions'=>array('key LIKE'=>"{$index}.%"), 'order'=>'title'));
		$data = array();
		foreach($res as $row) {
			$key = substr($row['Data']['key'], strlen("{$index}."));
			$data[$key] = $flatten ? $row['Data']['value'] : $row['Data'];
		}
		return $data;
	}
	
}


?>